%% Licensed to the Apache Software Foundation (ASF) under one
%% or more contributor license agreements.  See the NOTICE file
%% distributed with this work for additional information
%% regarding copyright ownership.  The ASF licenses this file
%% to you under the Apache License, Version 2.0 (the
%% "License"); you may not use this file except in compliance
%% with the License.  You may obtain a copy of the License at
%%
%%   http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.

sequenceDiagram
    Note over Airflow Repo: pull request
    Note over Tests: pull_request<br>[Read Token]
    Note over Build Images: pull_request_target<br>[Write Token]
    activate Airflow Repo
    Airflow Repo -->> Tests: Trigger 'pull_request'
    activate Tests
    Tests -->> Build Images: Trigger 'pull_request_target'
    activate Build Images
    Note over Build Images: Build info
    par 3.6, [3.7, 3.8, 3.9]
        activate GitHub Registry
        GitHub Registry ->> Build Images: Pull CI Images from Cache
        deactivate GitHub Registry
        Note over Build Images: Build CI Images<br>[COMMIT_SHA]
    end
    par No CI image
        Note over Tests: Build info<br>Which tests?<br>Which Python?
    and
        Note over Tests: OpenAPI client gen
    and
        Note over Tests: Test UI
    and
        Note over Tests: Test examples<br>PROD image building
    end
    par 3.6, [3.7, 3.8, 3.9]
        activate GitHub Registry
        Build Images ->> GitHub Registry: Push CI Images
        Note over GitHub Registry: Tagged CI Images<br>[COMMIT_SHA]
    end
    par 3.6, [3.7, 3.8, 3.9]
        GitHub Registry ->> Build Images: Pull PROD Images from Cache
        Note over Build Images: Build PROD Images<br>[COMMIT_SHA]
    end
    loop Wait for CI images
        par 3.6, [3.7, 3.8, 3.9]
            Tests ->> Tests: Check CI Images
            Note over Tests: Wait for<br>[COMMIT_SHA]
        end
    end
    par 3.6, [3.7, 3.8, 3.9]
        GitHub Registry ->> Tests: Pull CI Image
        Note over Tests: Verify CI Image
    end
    deactivate GitHub Registry
    par 3.6, [3.7, 3.8, 3.9]
        opt Needed?
            Note over Tests: Run static checks
        end
    and
        opt Needed?
            Note over Tests: Run basic <br>static checks
        end
    and
        opt Needed?
            Note over Tests: Build docs
        end
    and
        opt Needed?
            Note over Tests: Tests
        end
    and
        opt Needed?
            Note over Tests: Test provider <br>packages build
        end
    and
        opt Needed?
            Note over Tests: Helm tests
        end
    end
    par 3.6, [3.7, 3.8, 3.9]
        Build Images ->> GitHub Registry: Push PROD Images
        activate GitHub Registry
    end
    deactivate Build Images
    Note over GitHub Registry: Tagged PROD Images<br>[COMMIT_SHA]
    loop Wait for PROD images
        par 3.6, [3.7, 3.8, 3.9]
            Tests ->> Tests: Check PROD Images
            Note over Tests: Wait for<br>[COMMIT_SHA]
        end
    end
    par 3.6, [3.7, 3.8, 3.9]
        GitHub Registry ->> Tests: Pull PROD Image
        Note over Tests: Verify PROD Image
    end
    deactivate GitHub Registry
    par 3.6, [3.7, 3.8, 3.9]
        opt Needed?
            Note over Tests: Run Kubernetes <br>tests
        end
    and
        opt Needed?
            Note over Tests: Run Kubernetes <br>upgrade tests
        end
    end
    Tests -->> Airflow Repo: Status update
    deactivate Airflow Repo
    deactivate Tests
